Top 10k strings from Interactive BASIC Programming (1985)(Eigen Software)(Tape 2 of 3 Side A).tzx
in <root> / bin / z80 / software / Sinclair Spectrum Collection TOSEC.exe / Sinclair ZX Spectrum - Utilities & Educational / Sinclair ZX Spectrum - Utilities & Educational - [TZX] (TOSEC-v2007-01-01) /
Back to the directory listing
8 column=column+1 8 (row,column) 7 column=column-1 6 POKE USR 4 IF SCREEN$ 3 column=column+c 3 a$="second" 3 a$="first" 3 Wait for first key press 3 If key not pressed then repeat key test 3 ;"y out of range, try again": 3 ;"x out of range, try again": 3 "Please enter the y-coordinate for your first point ";y 3 "Please enter the x-coordinate for your first point ";x 3 PRINT AT 3 10,c+1;" 3 00001111 2 several lines of program 2 row,column;"X" 2 row,column;" 2 RANDOMIZE USR 2 LEVEL=LEVEL+1 2 An alternative to GOTO 1 2 ;"toggle sound: SPACE & ENTER" 2 ;"help: CAPS SHIFT & ENTER"; 2 ;"forward: SYMBOL SHIFT & SPACE"; 2 ;"backward: SYMBOL SHIFT & ENTER"; 2 ;"WARNING: if you enter 2 ;"Loading, please wait!" 2 ;"Interactive BASIC Programming"; 2 ;"Copyright 2 , it must be followed by 2 the Solution, then 2 statement like 2 r*2,c*3-1;r*c 2 Run the program in this Learning Element. 2 Each of the previous loops contained a 2 1985 Eigen Software" 2 10 2 00010100, 2 EIGEN SOFTWARE"; 2 PRINT AT 2 where 2 create reality" 2 FOR 2 PRINT AT 1 x,y 1 without committingourselves to the new coordinateslest they lie off the screen. 1 will wait for ever or until you press a key! (Try entering 1 will count down from 1 will cause the program to halt for one second (or until a key is pressed). Try entering 1 which is increased by one after each game. 1 we could have checked whether 1 the space would appear at 10,31 and the 1 the last statement in the loop. 1 statements: one group for lower case letters, the other group for capital letters.e.g 1 statements must be compatible e.g. a string mustbe read into a string variable. 1 statements cannot exceedthe number of 1 statement. 1 statement. 1 statement with a 1 statement will take account of the 1 statement will already have done the job! 1 statement 1 state- ments to help us with user- defined graphics? Try this 1 score=score+1 1 score=score+1 1 s indicate ink colour and 1 s indicate paper colour. The eightbinary numbers that form a user-defined graphics character are stored using eight statements like 1 row=row-1: 1 row=row+r: 1 row=row+1: 1 row,column;.... 1 row,column;"X";#0 1 row,column;"*" 1 rest of program 1 on rows 0 & 21and a 1 must be decreased by one and 1 module f 1 module e 1 loop. Modify your program to include the score. 1 list that begins with the first 1 lineboth linec 1 line and the 1 items (other-wise error E will occur; look itup in Appendix B {SCREEN REPORTSend of Chapter 4}). The 1 item to be 1 item of the first 1 item was a string ( 1 item found on line 1 instead of 1 if either 1 i*100+j*10+k=i^3+j^3+k^3 1 have to be start-ed off with specific numbers. These variables must be altered in order to move the graphic character. 1 has the advantage that, unlike 1 goes into 1 gives the empty string. Run this program and experiment by pressing various keys (with and without shift). 1 gives a whole number between 1 and 20 inclusive. 1 gives a random number between 1-30. 1 etc. is very long winded. Surelythere must be a better, more compact way of creating user- defined graphics. Well there is (surprise, surprise!). We can store the eight binary numbers in a 1 etc. but only if 1 control variable 1 condition 1 1 condition 1 1 column=column+n 1 column=column+c 1 change for next time 1 c 1 c 1 binarynumber 1 better than INK 7 1 better than INK 0 1 being some high line number that the main part of theprogram is unlikely to run into)At line 6000 put a suitable message such as 1 automatically forms a new 1 and try running this updatedversion. 1 a+b+c=a*b*c 1 a$="second": 1 a 130 1 a 1 We could put the binary numbers into a DATA statement 1 This gives numbers 1 to 10 on the top row and the same numbersrunning down the left hand side.If we allow three columns for each number on the top row then the display should be quite acceptable. We can also leave a row between each of the numbers on the left. (Read this a few times!) 1 These lines should be placed straight after the border printing lines. Notice that the 1 THEN STOP 1 THEN PRINT 1 THEN PRINT 1 THEN GOTO 1 Scrutinizer 1 Programming 1 PRINT AT INT 1 Now write a program that finds all the values of i, j and k forwhich ijk=i 1 Now what exactly is this game about? It should start off with an x (or some other character) in the middle of the screen and draw a snake of preset length without bumping into a border or the snake. We'll put in some obstacles and a score too. You could call this game SNAKEX. 1 Multiplication table 2 1 Multiplication table 1 1 Make sure that the 1 MODULE F 1 MODULE E 1 Let's use two variables: 1 LEVEL=LEVEL+1 320 1 LEVEL=1 1 Interactive 1 Important: it is meaningless to try to use staggered loops e.g. 1 I 1 HISCORE=SCORE 1 Good fun,isn't it! 1 Flexible zip 1 Created with Ramsoft MakeTZX 1 Chequered border 1 Check for a blank space using 1 An even more flexible zip 1 A couple of lads 1 ? Well, whenever the Spectrum is using numbers, smalldiscrepancies creep in. These are removed when the numbers areprinted (a lower number of significant digits). Write a program that shows the differences between 1 =21 since the 1 =2 or if 1 =0. Use 1 ;"y - up/left"; 1 ;"y u i"; 1 ;"wait for a key to be pressed" 1 ;"u - up"; 1 ;"plot next pixel" 1 ;"n - down"; 1 ;"m - down/right" 1 ;"long live the Z80!" 1 ;"j - right"; 1 ;"i - up/right"; 1 ;"h - left"; 1 ;"can the point be plotted?" 1 ;"b - down/left"; 1 ;"b n m" 1 ;"ask for starting point" 1 ;"an allowable key?" 1 ;"a+b+c=a*b*c": 1 ;"You should run this program again and copy out the summary on paper." 1 ;"We could start the program by asking for a starting point, clearing the screen, and plotting the first point" 1 ;"We can use y, u, i, h, j, b, n, m to plot lines and Y, U, I, H, J, B, N, M to delete lines" 1 ;"That was only a rough plan and we'll probably have to modify it later on. Nevertheless it is a good start."; 1 ;"Score = ";score 1 ;"Repeat the last part." 1 ;"Press any key to continue": 1 ;"Learning Module F" 1 ;"Learning Module E" 1 ;"Follow this by instructions that check for and act upon a key press." 1 ;"CLS, plot first point" 1 ;" Let's allocate the following symbols to these directions:"; 1 ; and right for 1 7 lineboth 1 6,c*3-1;3*c 1 20+LEVEL 1 13,26,81 110 1 11110000 1 11110000 1 100 1 10,10;" "; 1 10,"doggy" 1 10 1 01010100, 1 01010010 1 00100010 1 00011011 1 00001111 1 0,10;score 1 0 1 . Write a program that prints a chequered border aroundthe edge of the screen. 1 . Use several 1 . The program used 1 . The programmer had to make sure thatthe first 1 . Compare 1 . (ijk is a three-digit number, not i*j*k.) 1 . In order to move left 1 . In order to make sense of these state- ments we will have to use 1 . Then interchange lines 1 . For capital leters use 1 . N.B.G. 1 . . . 1 . . . 1 . Enter 1 . 1 , you are not restrict-ed to a specific row. 1 , though this isn't a real error).Instead of 1 , pause, delete the 1 , deliberately enter out-of-range numbers. 1 , at the top of the 1 *30+1);"*": 1 ). You would probably want to take action other than 1 ), tells the Spectrum to place the first 1 ) would be 1 ) in the loop but you can use as many lines as you want. The numerical variable 1 ) change the row part of the 1 ) and couldonly be read into a string variable. Try running the above program then enter 1 ) and then print a congratulatory message. You could even record the name of the highest scorer by using 1 ) this program for later use. 1 (tabulate) is used to take the printing position onto a specific column in the current row (or on the next row if the column has already passed). 1 (say) in an 1 (a-b)<0.00001 1 (Note: this 1 "These are very small numbers:": 1 "Some of the numbers are negativeDo you understand why?" 1 "Monday","Tuesday","Wednesday" 1 " was printed 1 " Summary:" 1 " 140 1 " 120 1 " 1 you will have tomake a careful plan. 1 x<0 OR x>255 1 x+xx>255 1 written before a number of 0s and 1s tells your Spectrum that the number is a binary one. 1 would be read into the variable 1 without a line number is the same as 1 with values of -1,0 or 1. Eachtime round the loop update 1 with the loop structurein 1 with the score after a "CRASH!". If 1 will be about right for your program: up-date it now. Incidentally, 1 tocount the number of obstacles. The function 1 to print the same chequered border but in clock- wise order. (Yes, the end resultis the same but it looks better when running!) Retain ( 1 to make sure that there are no stray characters on the screen. Then produce the border. Start off row and column. 1 this program 1 this means: repeat the line(s)between the 1 the first line inside the 1 that is kept equal to the number of Xs successfullyprinted. Start 1 statementsfor detecting and acting upon key presses. Use a string variable that can have values "first" and "second" only. We need to alternate between 1 statements: 1 statements, in the order inwhich they appear. This list maywell be a mixture of numbers andstrings. Successive 1 statements to check for and act upon specific key presses. Use 1 statements to test for specific keys. Put numbers in 1 statements jump to thisline. 1 statements for the y-coordinate. Then use 1 statements contain items separated by commas. In fact these items can even be variable names. 1 statements can be placed anywhere in a program. A 1 statements should consist of altering 1 statement. We can use a false 1 statement. If you were to 1 statement. A 1 statement is very useful but rather slow. You haveto press ENTER too. The 1 statement is before the point of return after each successful game. Just use 1 statement in order to make the computer wait for the first key press. 1 statement could have been 1 statement collects an item from a 1 statement by 1 statement allows usto repeat a set of instructions indefinitely. However, there is some BASIC for repeating a set of instructions for a specified number of times. E.g. 1 statement in order to re-start the program. 1 statement that sets the ink to its regularcolour for lower case letters and sets the regular paper colour for capital letters. If no key is pressed then check again. Write the next part. 1 statement must follow an 1 statement 1 state- ments will copy successive 1 starts at 1 and goes up to 10. Can you see how nested loops might help? 1 starts at 1 and goes up to 10. 1 so we know that the t character is to be found at 1 should take values -1, 0 or +1 so that we can use 1 should give a pause that is long enoughfor the player to read the "CRASH!" message. Follow this with a suitable 1 row=row+r 1 row=row+1: 1 row,column;"x" 1 row, column;" 1 row =row-1: 1 printed the same as 1 or between 1 off at 0 and use 1 obstacles, without modification. 1 number 1 must contain -1 and 1 must become 0. We need to distinguish between upper and lower case letters. The final 1 means make the expression positive (all negative numbers are less than 0.00001!) 1 means increase by 1 loop: 1 loop, with each successive level. Why not have a variable called 1 loop! These are called nested loops. We will use this idea to produce a 10x10 multiplication table in the formof a grid. 1 loop with the control variable taking values from 0 to 31 might be useful. However, each time around the loop similar instructions have to be executed. If 1 loop though 1 loop produces eight 1 loop inside another 1 loop in order to have a definite length for the snake. Let's also use two more numeric variables: 1 loop for the columns of 1 loop control variable) for your snake. 1 loop and 1 loop in order to solve a puzzle. Is it possible to find three numbers which when added together give a number equal to their product. i.e. if the numbers are a, b, and c then canwe have a+b+c=a*b*c? 1 linex where linex contains the 1 linel 1 line, 20 times. This is known as a 1 lay outside the range 0-21 and whether 1 lay outside the range 0-31. Our game is muchbetter for using the first method though. 1 j 1 items into variables. The numberof 1 items from all 1 items in the last 1 item. e.g 1 item of the 1 it will calculate the difference before considering a lower number of significant digits. This difference will be a small number which can be printed. 1 isthe beginning of key testing, will be useful to you. Now finish your program. 1 is within the permitted range. In this way we can test 1 is true. 1 is the line number for printing the left characters 1 is the control variable then we could use 1 is the character you chose for the border (and might not actually be a 1 is printed. You can design all21 user-defined graphics in a similar way to that just described. 1 is printed at the nextcharacter position which is 11,0Modify your program so that it moves the little man (or some other "character"!) either towards the left or the right depending on whether h or j is being pressed. No motion if h orj is not pressed. 1 is pressed; down for 1 is not changed. Hence 1 is made up of 1 is higher than 1 is equal to a random number between 0 and 1 which may be equal to 0 but is never equal to 1. We have to putobstacles between rows 1 and 20 and columns 1 and 30 (thus avoiding the border). 1 is aline number ( 1 is a time interval measured in 1/50s of a second. So 1 is a row and 1 is a column, finds the character at 1 is almost equal to 1 into a numerical variable. The second 1 inside the loop and this can be a big help. There is no need, however, to use 1 inside the X printing loop. 1 in 1 if in range; pause and go to key test-ing. 1 i=1 to 100: 1 i*100+j*10+k=i*i*i+j*j*j+k*k*k THEN 1 i 1 has values from 0 to 7. These instructions would assign (give) the character to the 1 guided you in the right direction. However, when you write programs without the help of 1 gives a random number between 1 and 20. Similarly, 1 function simply finds the whole number (integer) part of 1 function (a function is something that carries out a specific task) always gives the character for the key currently being pressed. If a key is not being pressed or two or more keys are being pressed (shift keys are the exception) then 1 for? The answer is: for all the best programs. Write a program that moves a graphic character left if 1 for now. However, we could make sure that we don't "bump" into any other character by using something like: 1 for changes in 1 for repetition. 1 followed on the next line by 1 followed by 1 each time around the loop. A negative 1 contained 30. So " 1 condition 2 1 column=column-1 1 column=column-1 1 column=column+c 1 column=column+1 1 can be useful. 1 c 1 c 1 but we'llkeep 1 at the next position, pause and so on. A 1 asfollows 1 are the changes in 1 andits name can only be one letter long. Add line numbers to the program given above and run it. 1 and was incremented (increased by one) up to a final value of 1 and the string 1 and print a 1 a$="big" 1 Your program should now be complete. You could put in an extra key test that would clear the screen. Perhaps you can think of further enhancements. 1 You will probably have foundthat the graphic character movestoo fast and when the program tried to print outside the screen an error message was given. If you make the border and paper colours different thenit will be easier to see, and therefore avoid, the border. Youcan slow down the program using 1 You will need to use something like 1 You will need four user- defined graphics. Two for left motion and two for motion to theright. Use 1 You will have to increase the control variable for the snake printing 1 You will find that 1 You need two groups of 1 You might also want the program to pause after the "CRASH" print statement and then return to the beginning fora second game. There is a chancethat the player is still press- ing a key after the "CRASH!" printing line has been executed so it's not a good idea to use a 1 Write the first part of the program. Go as far as actually plotting a valid first point. 1 Write a program to find the numbers a, b and c given that they are whole numbers (integers) less than eleven. 1 When you run a program containing 1 When Spectrum comes across 1 What can we use 1 We will refer to the plan inwriting our picture-drawing program. The first step is to ask for the starting point. Whatis required is a x-coordinate which must lie in the range 0 to255 and a y-coordinate in the range 0 to 175. 1 We have the makings of a game with this program! The error messages that appear when we try to leave the screen are rather irksome. We can get around this by drawing our own border and checking whether printing would overwrite it. Remember that you have already written a program that produces a border. Copy it into the beginning of your last program (the game program!). 1 We could use 1 Use variables 1 Use the graphic character on the sixth {eighth} key, firstrow. Use 1 Use just two 1 Use a loop and 1 Think up an idea for a program that uses nested loops, write and run it. (A calendar to be sent to a printer?) 1 There is a modification to the 1 The snakex program was, in one sense, inadequate in that you didn't have an overview, no real feeling for the direction we were taking. That didn't really matter since 1 The program should do the following: input and print a starting pointdetect a keypress update 1 The loop structure is: 1 The graphics character 1 The general structure is: 1 The Spectrum keeps track of the next 1 The Greek letter psi that forms part of the Eigen Softwarelogo (Schrodinger Equation) can be assigned to the e key with: 1 THEN STOP 1 THEN PRINT 1 THEN GOTO 1 Suppose the h key is being pressed, it would be detected by 1 Start the program with 1 So in order to move the snake upwards use 1 Remember to use brackets in 1 People who are trying to learn BASIC programming are often told that they should use flowcharts: a collection of symbols used to plan a program. Flowcharts are supposed to makethe program easier to write and then easier to understand at a later date or by someone else. Only newcomers to computing use flowcharts (because they've beentold to!). The chances of someone else looking at your program are somewhat remote. We should always make some plans though. The next program enablesyou to draw pictures on the screen. Run the program found inthis Learning Element. 1 PRINT INK 1 Organise 1 Once the player presses a key to move (or grow) the snake the snake should continue in that direction until a differentkey is pressed (or the snake hasgrown long enough). Otherwise the game would be too easy. We'll use a 1 Of course, when the snake bumps into the border or itself the program still produces an error message (indicating 1 Of course instead of using a border and 1 Now we'll combine an 1 Now for the results. We'll print them in red. Consider one row at a time: 1 Now for some obstacles. We can use the variable 1 Now for key pressing. Read through the next part slowly, a few times. If you don't quite follow it don't worry, just continue with the following Learning Elements and return to this point if you are still unsure. 1 Notice that in the last program the 1 Notice that after the program has run, a character is printed at the beginning of row 11. This happens because the last print statement was 1 Nest three loops together and test for a+b+c being equal to a*b*c. 1 Modify your program for the following diagonal directions: y for up/left, i for up/right, b for down/left and m for down/ right. 1 Make sure that the 1 Look at our solution, please. Notice the 1 It will be useful to use an extended form of the 1 It is possible to have a 1 In the last program the 1 In order to print the obstacles use: 1 In finding i, j and k you will have found only two sets ofvalues if you used: 1 If you don't understand what has been said about accuracy it doesn't really matter. All this boils down to is: unless you are sure that 1 If we use: 1 If the player is able to complete the snake in full then let him/her play again but at a higher level. You could do several things for a higher level: speed up the snake, lengthen the snake or print obstacles. Modify your program so that many levels exist: each one with a longer snake than the previous level. 1 IF INKEY$ 1 I think it's about time we looked at user-defined graphics.These are characters whose shapewe can design. There are 21 characters available: they are allocated to letters a - u and accessed by pressing the apropriate key while in graphic mode. Each character square is made up of eight rows of dots (pixels). An eight-digit binary number (one that is made up of 0s and 1s only) is used to represent each row of eight pixels. 1 I 310 1 How would you keep a score going? Well how about a variablecalled 1 How can we use 1 How can we get the little man to walk across the screen? We have to print 1 How can the program find outwhether it is about to print on the border? 1 How about keeping track of a high score. Use the variable 1 Have you tested your programyet? If not then do so now. Whenasked for 1 For diagonal movement both row and column must be altered at the same time e.g 1 Follow the 1 Finally use: 1 Enter these lines directly. Then get into graphics mode (CAPS SHIFT and GRAPHICS {GRAPH}) and press the e key. 1 Don't worry! The Spectrum, like all computers, is slighty inaccurate when it works out sums. Inaccurate to the extent of about 1 in 2 000 000 000 (tenth significant figure)! Thislevel of accuracy is quite acceptable and doesn't cause anyproblems at all if you know whatyou're doing. But why is 1 Design two user-defined graphic characters that depict two frames of the motion of a little man walking. 1 Compare your program with the program contained in this Learning Element. 1 Combine the print statementfrom 1 Allocate separate letters to each frame. Remember that thebinary numbers are made up of eight digits. These binary digits (also called bits) can only be 0 or 1. 1 All that remains is to checkwhether the new coordinates are in range; go to the beginning of key testing if out of range; update and plot 1 8,c*3-1;4*c 1 7 1 6,7,0.26,6218,3,-28.1 1 5 150 1 5 130 1 4,c*3-1;2*c 1 236,"BLUE","RED",-9298, 1 23 1 20,16;"t" 1 20 1 2 110 1 11110000 1 1 11110000 1 10 1 10 1 10 1 00111100, 1 00010101 1 00010100 1 00010000 1 00010000 1 00001100 1 00000010, 1 00000000, 1 00000000, 1 0,i*3;i 1 0,2;"score= ";score 1 0,0,2,60,84,20,20,0 1 ..... are integers (whole numbers), use 1 ..... (for example).This checks to see if 1 ..... How can this be? Well, enter andrun this program: 1 ..... but you will have found all six sets if you used: 1 -67,35 120 1 (or some otherposition of your choice). Then enter 1 (expression) 1 (Press CAPS SHIFT and BREAK {BREAK} to stop the program.) 1 "x out of range, try again": 1 "p"+i,binarynumber 1 "Please enter the x-coordinate for your first point ";x 1 would print 2. 1 then the previous picture will be deleted. Enter and run this program: 1 statement. Use a similar pair of 1 is called a 1 inside the snake printing 1 i for up/right: 1 but let 1 Torridon 1 PRINT AT 1 POKE USR 1 Enter and runthis program. Then add 1 E.g. 1 Brew your own beer too! It's real easy and has gotto be the best pint in the worldbecause you can make it exactly how you want it. Anyway, only fools pay for the 'privilege' ofconsuming aqueous solutions of ethanol. Down with governments that suppress human rights - like the British Government. 1 Bake your own bread! It's cheaper and of a muchhigher quality than ALL shop- bought 'bread' and anyway why part with money for air? 1 statements and the eight data items are read in turn. 1 key but you could have used one from b to u instead. 1 items and 1 column 1 but you can influence this if you like. 1 POKE USR 1 will not be altered but 1 will give a number between 0 and20 (but not equal to 20), no good! 1 then copy the contents of 1 statement. 1 started at 1 loop. We've placed only one line( 1 POKE USR 1 INKEY$ 1 DATA BIN 1 statement. 1 statement is simply a place where you can save numbers and strings (text). The following are examples of 1 will still be executed each timearound the loop and the snake will continue to move. Modify your game choosing a suitable length ( 1 directly from the keyboard.) 1 RESTORE 1 PRINT AT 1 statements of the form: 1 and run again. 1 POKE USR 1 statements your Spectrum forms alist of all 1 condition 2 1 appropriately. 1 "h" indicates move left. 1 NEXT 1 Similarly for other directions. If no key is pressed 1 PRINT 1 NEXT 1 NEXT 1 with 1 NEXT 1 where 1 and 1 FOR 1 r,31;" 1 Notice that there is no need to use 1 set 1 This will give the top row of numbers. Write a second loop forprinting numbers down the left of the screen. 1 Then a similar pair of statements for 1 then 1 IF 1 PRINT AT 1 FOR 1 READ 1 Numbers and strings can be mixed. 1 NEXT 1 NEXT 1 FOR 1 will print O.K. if 1 NEXT 1 Now update your game program as suggested. 1 means carry out the 1 m for down/right: 1 If your program doesn't do this then compare it to the program in this Learning Element. 1 b for down/left: 1